package org.alex.sample.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.Length;

@Entity
@Table(name = "exam_user")
public class User implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue
	@Column(name = "id", nullable = false)
	private Integer id;
	
	@Column(name = "user_name", nullable = false)
	@Length(min = 1, max = 30, message = "用户名不能为空且不超过30个字符")
	private String userName;
	
	@Column(name = "name", nullable = false)
	@Length(min = 1, max = 15, message = "姓名不能为空且长度不能超过15个字符")
	private String name;
	
	@Column(name = "gender", nullable = false)
	@Length(min = 1,max = 1,message = "请输入男或女")
	private String gender;
	
	@Column(name = "birthday", nullable = false)
	@Length(min = 1,max = 30,message = "请输入出生日期")
	private String birthday;
	
	@Column(name = "tel", nullable = false)
	@Length(min = 11 ,max = 11, message = "请输入长度11位的手机号")
	private String tel;
	
	@Column(name = "address", nullable = false)
	@Length(min = 1,max = 50,message = "住址不能为空")
	private String address;
	
	@Length(min = 6, max = 32, message = "密码长度为6-32位字符")
	@Column(name = "password", nullable = false)
	private String password;
	
	@Email(message = "请输入邮箱")
	@Column(name = "email", nullable = false)
	private String email;
	
	@Column(name = "last_lock_time", nullable = true)
	private Date lastLockTime;
	
	@Column(name = "login_fail_count", nullable = true)
	private Integer loginFailCount;
	
	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Set<ExamUserSubject> examUserSubject;
	
	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	private Set<ExamUserRole> examUserRole;
	
	@OneToMany(mappedBy = "user", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	private Set<ExamScore> examScore;
	
	
	public User(Integer id, String userName, String name, String gender, String birthday, String tel, 
			String address, String password, String email, Set<ExamUserSubject> examUserSubject, 
			Date lastLockTime, Integer loginFailCount) {
		this.id = id;
		this.userName = userName;
		this.name = name;
		this.gender = gender;
		this.birthday = birthday;
		this.tel = tel;
		this.address = address;
		this.password = password;
		this.email = email;
		this.examUserSubject = examUserSubject;
		this.lastLockTime = lastLockTime;
		this.loginFailCount = loginFailCount;
	}
	
	public User() {
		
	}
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public Set<ExamUserSubject> getExamUserSubject() {
		return examUserSubject;
	}

	public void setExamUserSubject(Set<ExamUserSubject> examUserSubject) {
		this.examUserSubject = examUserSubject;
	}
	

	public Date getLastLockTime() {
		return lastLockTime;
	}

	public void setLastLockTime(Date lastLockTime) {
		this.lastLockTime = lastLockTime;
	}

	public Integer getLoginFailCount() {
		return loginFailCount;
	}

	public void setLoginFailCount(Integer loginFailCount) {
		this.loginFailCount = loginFailCount;
	}

	public Set<ExamUserRole> getExamUserRole() {
		return examUserRole;
	}

	public void setExamUserRole(Set<ExamUserRole> examUserRole) {
		this.examUserRole = examUserRole;
	}

	public Set<ExamScore> getExamScore() {
		return examScore;
	}

	public void setExamScore(Set<ExamScore> examScore) {
		this.examScore = examScore;
	}
	
}
